package cn.itutu.demo.junit;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertEquals;

/**
 * Created by itutu on 2018/4/16.
 * Description: Junit参数化测试
 */
@RunWith(Parameterized.class)
public class Junit4Demo_Parameter {
    Calculator calculator = new Calculator();
    private int number1;
    private int number2;
    private int answer;

    public Junit4Demo_Parameter(int num1, int num2, int ans) {
        number1 = num1;
        number2 = num2;
        answer = ans;
    }

    @Parameters
    public static Collection calNumber() {
        return Arrays.asList(new Object[][]{
                {1, 2, 3},
                {0, 0,0},
                {-4,8,4}
        });
    }

    @Test
    public void testAdd(){
        assertEquals(answer, calculator.add(number1,number2));
        System.out.println(number1 + "+" + number2 + "=" + answer);
    }
}
